﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using System.Collections;
using BBMS.DLL.Base;
using System.Collections.Specialized;
namespace BBMS.DLL.DataContract
{
    public class NghanhHangList : BBMS.DLL.Base.ObjectList
    {
        public override void LoadData()
        {
            if (hash == null) hash = new System.Collections.Hashtable();
            hash.Clear();
            try
            {
                MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select * from branch";
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
                    this.Add(new NganhHang(rd["Ma"].ToString(), rd["Ten"].ToString(), rd["TenTiengAnh"].ToString()));

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch
            {
                this.hash.Clear();
            }
        }

        public static NameValueCollection getAllBranch()
        {
            NganhHang n = new NganhHang();
            NameValueCollection list = new NameValueCollection();
            MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
            try
            {
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select Ma, Ten from " + n.TableName;
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
                    list.Add(rd["Ma"].ToString(), rd["Ten"].ToString());

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch 
            {
                throw;
            }
            return list;
        }
    }
}
